import {
	toHyphen
} from '@/util/hump-line-convertor.js'
import {
	startWith
} from '@/util/str.js'
function builderComponentName(prefix, path) {
	let componentName = ''
	let fileName = path.substring(path.lastIndexOf('/') + 1, path.length)
	if (['index.vue', 'index.ce.vue'].includes(fileName)) {
		componentName = path.substring(path.indexOf(prefix + '/'), path.lastIndexOf('/'))
		// console.log('component-name-builder:modules:componentName1', componentName);
		let wordArray = componentName.split('/')
		for (var i = 0; i < wordArray.length; i++) {
			let word = wordArray[i]
			word = toHyphen(word)
			wordArray[i] = word
		}
		componentName = wordArray.join('-')
		// componentName = componentName.replace('/','-')
		componentName = componentName.toLocaleLowerCase()
	} else {
		componentName = fileName.substring(0, fileName.indexOf('.'))
		// console.log('component-name-builder：fileName',componentName);
		if (!startWith(componentName,prefix,true)) {
			componentName = prefix + componentName
		}
		componentName = toHyphen(componentName)
		componentName = componentName.toLocaleLowerCase()
	}
	// console.log('component-name-builder结果：',componentName);
	return componentName
}

export {
	builderComponentName
}